"""
工具函数模块
"""

import numpy as np
import cv2
import math
from typing import Tuple, List, Optional
from config import COLORS, POSTURE_THRESHOLDS, SCORING_WEIGHTS

def calculate_angle(point1: Tuple[float, float], 
                   point2: Tuple[float, float], 
                   point3: Tuple[float, float]) -> float:
    """
    计算三个点组成的角度
    
    Args:
        point1: 第一个点 (x, y)
        point2: 顶点 (x, y)
        point3: 第三个点 (x, y)
    
    Returns:
        角度值 (度)
    """
    # 计算向量
    vector1 = np.array([point1[0] - point2[0], point1[1] - point2[1]])
    vector2 = np.array([point3[0] - point2[0], point3[1] - point2[1]])
    
    # 计算角度
    cos_angle = np.dot(vector1, vector2) / (np.linalg.norm(vector1) * np.linalg.norm(vector2))
    cos_angle = np.clip(cos_angle, -1.0, 1.0)  # 防止数值误差
    angle = math.degrees(math.acos(cos_angle))
    
    return angle

def calculate_distance(point1: Tuple[float, float], 
                      point2: Tuple[float, float]) -> float:
    """
    计算两点之间的欧几里得距离
    
    Args:
        point1: 第一个点 (x, y)
        point2: 第二个点 (x, y)
    
    Returns:
        距离值
    """
    return math.sqrt((point1[0] - point2[0])**2 + (point1[1] - point2[1])**2)

def normalize_landmarks(landmarks, image_width: int, image_height: int) -> List[Tuple[float, float]]:
    """
    将MediaPipe的归一化坐标转换为像素坐标
    
    Args:
        landmarks: MediaPipe检测到的关键点
        image_width: 图像宽度
        image_height: 图像高度
    
    Returns:
        像素坐标列表
    """
    normalized_points = []
    for landmark in landmarks.landmark:
        x = landmark.x * image_width
        y = landmark.y * image_height
        normalized_points.append((x, y))
    
    return normalized_points

def get_posture_grade(score: float) -> str:
    """
    根据评分获取坐姿等级
    
    Args:
        score: 坐姿评分 (0-100)
    
    Returns:
        坐姿等级字符串
    """
    if score >= 90:
        return "excellent"
    elif score >= 75:
        return "good"
    elif score >= 60:
        return "fair"
    else:
        return "poor"

def get_grade_color(grade: str) -> Tuple[int, int, int]:
    """
    根据等级获取对应颜色
    
    Args:
        grade: 坐姿等级
    
    Returns:
        BGR颜色值
    """
    return COLORS.get(grade, COLORS['poor'])

# =============================================================================
# 新增：精细化坐姿评估函数
# =============================================================================

def calculate_head_desk_distance(landmarks: List[Tuple[float, float]], 
                                image_height: int) -> float:
    """
    计算头部与桌面的距离（基于头部在画面中的位置）
    
    Args:
        landmarks: 关键点坐标列表
        image_height: 图像高度
    
    Returns:
        头部距离评分 (0-100)
    """
    # 获取鼻子位置作为头部参考点
    nose = landmarks[0]  # NOSE
    
    # 计算头部在画面中的相对位置
    head_position_ratio = nose[1] / image_height
    
    # 理想的头部位置应该在画面的上1/3到中间位置
    ideal_min = 0.2  # 画面20%处
    ideal_max = 0.5  # 画面50%处
    
    if ideal_min <= head_position_ratio <= ideal_max:
        # 在理想范围内，距离适中
        distance_score = 100
    elif head_position_ratio < ideal_min:
        # 头部太高，距离过远
        distance_score = max(0, 100 - (ideal_min - head_position_ratio) * 400)
    else:
        # 头部太低，距离过近
        distance_score = max(0, 100 - (head_position_ratio - ideal_max) * 200)
    
    return distance_score

def calculate_neck_posture_comprehensive(landmarks: List[Tuple[float, float]]) -> Tuple[float, float, float]:
    """
    综合计算脖子姿态（前倾、侧倾、扭转）
    
    Args:
        landmarks: 关键点坐标列表
    
    Returns:
        (前倾角度, 侧倾角度, 扭转程度)
    """
    left_ear = landmarks[7]   # LEFT_EAR
    right_ear = landmarks[8]  # RIGHT_EAR
    left_shoulder = landmarks[11]  # LEFT_SHOULDER
    right_shoulder = landmarks[12] # RIGHT_SHOULDER
    nose = landmarks[0]       # NOSE
    
    # 1. 计算脖子前倾角度
    # 使用耳朵中点到肩膀中点的角度
    ear_center = ((left_ear[0] + right_ear[0]) / 2, (left_ear[1] + right_ear[1]) / 2)
    shoulder_center = ((left_shoulder[0] + right_shoulder[0]) / 2, (left_shoulder[1] + right_shoulder[1]) / 2)
    
    # 计算脖子与垂直线的角度
    neck_vector = (ear_center[0] - shoulder_center[0], ear_center[1] - shoulder_center[1])
    vertical_vector = (0, -1)  # 垂直向上
    
    # 计算前倾角度
    dot_product = neck_vector[0] * vertical_vector[0] + neck_vector[1] * vertical_vector[1]
    neck_length = math.sqrt(neck_vector[0]**2 + neck_vector[1]**2)
    if neck_length > 0:
        cos_angle = dot_product / neck_length
        cos_angle = np.clip(cos_angle, -1.0, 1.0)
        forward_angle = math.degrees(math.acos(cos_angle))
    else:
        forward_angle = 0
    
    # 2. 计算脖子侧倾角度
    ear_diff = abs(left_ear[1] - right_ear[1])
    ear_distance = calculate_distance(left_ear, right_ear)
    if ear_distance > 0:
        side_tilt_angle = math.degrees(math.asin(min(ear_diff / ear_distance, 1.0)))
    else:
        side_tilt_angle = 0
    
    # 3. 计算脖子扭转程度
    # 基于鼻子相对于耳朵中点的偏移
    nose_offset = abs(nose[0] - ear_center[0])
    ear_width = abs(left_ear[0] - right_ear[0])
    if ear_width > 0:
        twist_ratio = nose_offset / ear_width
    else:
        twist_ratio = 0
    
    return forward_angle, side_tilt_angle, twist_ratio

def calculate_shoulder_posture_detailed(landmarks: List[Tuple[float, float]]) -> Tuple[float, float, float, float]:
    """
    详细计算肩膀姿态（高低差、前后差、内收程度、对称性）
    
    Args:
        landmarks: 关键点坐标列表
    
    Returns:
        (高低差角度, 前后差距, 内收程度, 对称性评分)
    """
    left_shoulder = landmarks[11]   # LEFT_SHOULDER
    right_shoulder = landmarks[12]  # RIGHT_SHOULDER
    left_elbow = landmarks[13]      # LEFT_ELBOW
    right_elbow = landmarks[14]     # RIGHT_ELBOW
    
    # 1. 肩膀高低差
    height_diff = abs(left_shoulder[1] - right_shoulder[1])
    shoulder_distance = calculate_distance(left_shoulder, right_shoulder)
    if shoulder_distance > 0:
        height_diff_angle = math.degrees(math.asin(min(height_diff / shoulder_distance, 1.0)))
    else:
        height_diff_angle = 0
    
    # 2. 肩膀前后差（基于肩膀到肘部的距离差异）
    left_shoulder_elbow_dist = calculate_distance(left_shoulder, left_elbow)
    right_shoulder_elbow_dist = calculate_distance(right_shoulder, right_elbow)
    front_back_diff = abs(left_shoulder_elbow_dist - right_shoulder_elbow_dist)
    
    # 3. 肩膀内收程度（基于肩宽相对于理想肩宽的比例）
    shoulder_width = calculate_distance(left_shoulder, right_shoulder)
    # 假设理想肩宽约为图像宽度的1/4到1/3
    ideal_shoulder_width_ratio = 0.28  # 经验值
    current_ratio = shoulder_width / 640  # 假设标准图像宽度
    shoulder_narrowing = max(0, ideal_shoulder_width_ratio - current_ratio)
    
    # 4. 肩膀对称性（综合评估）
    symmetry_score = 100 - (height_diff_angle * 2 + front_back_diff * 10 + shoulder_narrowing * 100)
    symmetry_score = max(0, min(100, symmetry_score))
    
    return height_diff_angle, front_back_diff, shoulder_narrowing, symmetry_score

def calculate_spine_alignment_advanced(landmarks: List[Tuple[float, float]]) -> Tuple[float, float, float]:
    """
    高级脊柱对齐评估（颈椎、胸椎、腰椎对齐）
    
    Args:
        landmarks: 关键点坐标列表
    
    Returns:
        (颈椎角度, 胸椎角度, 整体脊柱评分)
    """
    left_ear = landmarks[7]
    right_ear = landmarks[8]
    left_shoulder = landmarks[11]
    right_shoulder = landmarks[12]
    left_hip = landmarks[23]
    right_hip = landmarks[24]
    
    # 计算关键点的中点
    ear_center = ((left_ear[0] + right_ear[0]) / 2, (left_ear[1] + right_ear[1]) / 2)
    shoulder_center = ((left_shoulder[0] + right_shoulder[0]) / 2, (left_shoulder[1] + right_shoulder[1]) / 2)
    hip_center = ((left_hip[0] + right_hip[0]) / 2, (left_hip[1] + right_hip[1]) / 2)
    
    # 1. 颈椎角度（耳朵到肩膀的角度）
    cervical_angle = calculate_angle(ear_center, shoulder_center, (shoulder_center[0], shoulder_center[1] + 100))
    
    # 2. 胸椎角度（肩膀到髋部的角度）
    thoracic_angle = calculate_angle(shoulder_center, hip_center, (hip_center[0], hip_center[1] + 100))
    
    # 3. 整体脊柱评分
    # 理想的脊柱应该接近垂直
    ideal_angle = 90
    cervical_deviation = abs(cervical_angle - ideal_angle)
    thoracic_deviation = abs(thoracic_angle - ideal_angle)
    
    spine_score = 100 - (cervical_deviation * 2 + thoracic_deviation * 1.5)
    spine_score = max(0, min(100, spine_score))
    
    return cervical_angle, thoracic_angle, spine_score

def calculate_sitting_stability(landmarks: List[Tuple[float, float]]) -> float:
    """
    计算坐姿稳定性（基于重心分布）
    
    Args:
        landmarks: 关键点坐标列表
    
    Returns:
        稳定性评分 (0-100)
    """
    left_shoulder = landmarks[11]
    right_shoulder = landmarks[12]
    left_hip = landmarks[23]
    right_hip = landmarks[24]
    
    # 计算上身重心
    upper_center = ((left_shoulder[0] + right_shoulder[0]) / 2, (left_shoulder[1] + right_shoulder[1]) / 2)
    
    # 计算下身重心
    lower_center = ((left_hip[0] + right_hip[0]) / 2, (left_hip[1] + right_hip[1]) / 2)
    
    # 计算重心偏移
    center_offset = abs(upper_center[0] - lower_center[0])
    
    # 计算肩宽作为参考
    shoulder_width = calculate_distance(left_shoulder, right_shoulder)
    
    # 稳定性评分
    if shoulder_width > 0:
        offset_ratio = center_offset / shoulder_width
        stability_score = max(0, 100 - offset_ratio * 200)
    else:
        stability_score = 50
    
    return stability_score

# =============================================================================
# 更新原有函数以适应新的评估标准
# =============================================================================

def calculate_spine_straightness(landmarks: List[Tuple[float, float]]) -> float:
    """计算脊柱直立度（更新版）"""
    _, _, spine_score = calculate_spine_alignment_advanced(landmarks)
    return spine_score

def calculate_shoulder_level_diff(landmarks: List[Tuple[float, float]]) -> float:
    """计算肩膀水平差异（更新版）"""
    height_diff_angle, _, _, _ = calculate_shoulder_posture_detailed(landmarks)
    return height_diff_angle

def calculate_neck_forward_angle(landmarks: List[Tuple[float, float]]) -> float:
    """计算脖子前倾角度（更新版）"""
    forward_angle, _, _ = calculate_neck_posture_comprehensive(landmarks)
    return forward_angle

def calculate_neck_side_tilt(landmarks: List[Tuple[float, float]]) -> float:
    """计算脖子侧倾角度（更新版）"""
    _, side_tilt_angle, _ = calculate_neck_posture_comprehensive(landmarks)
    return side_tilt_angle

def calculate_shoulder_symmetry(left_shoulder: Tuple[float, float],
                               right_shoulder: Tuple[float, float]) -> float:
    """
    计算肩膀位置对称性（左右肩膀前后位置差异）
    
    Args:
        left_shoulder: 左肩膀坐标
        right_shoulder: 右肩膀坐标
    
    Returns:
        对称性差异值（0-1之间，0表示完全对称）
    """
    # 计算左右肩膀的x坐标差异（表示前后位置）
    x_diff = abs(left_shoulder[0] - right_shoulder[0])
    
    # 计算肩膀宽度作为归一化基准
    shoulder_width = calculate_distance(left_shoulder, right_shoulder)
    
    if shoulder_width == 0:
        return 0.0
    
    # 归一化差异值
    symmetry_diff = x_diff / shoulder_width
    
    return min(symmetry_diff, 1.0)

def calculate_upper_body_lean(left_shoulder: Tuple[float, float],
                             right_shoulder: Tuple[float, float],
                             left_hip: Tuple[float, float],
                             right_hip: Tuple[float, float]) -> float:
    """
    计算上身前倾程度（基于肩膀相对于髋部的前后位置）
    
    Args:
        left_shoulder: 左肩膀坐标
        right_shoulder: 右肩膀坐标
        left_hip: 左髋部坐标
        right_hip: 右髋部坐标
    
    Returns:
        前倾程度值（0-1之间，0表示完全垂直）
    """
    # 计算肩膀中点和髋部中点
    shoulder_center = ((left_shoulder[0] + right_shoulder[0]) / 2,
                      (left_shoulder[1] + right_shoulder[1]) / 2)
    hip_center = ((left_hip[0] + right_hip[0]) / 2,
                  (left_hip[1] + right_hip[1]) / 2)
    
    # 计算垂直距离（躯干高度）
    vertical_distance = abs(shoulder_center[1] - hip_center[1])
    
    if vertical_distance == 0:
        return 0.0
    
    # 计算水平偏移（前倾距离）
    horizontal_offset = abs(shoulder_center[0] - hip_center[0])
    
    # 计算前倾比例
    lean_ratio = horizontal_offset / vertical_distance
    
    return min(lean_ratio, 1.0)

def calculate_sitting_width(left_shoulder: Tuple[float, float],
                           right_shoulder: Tuple[float, float],
                           image_width: int) -> float:
    """
    计算坐姿宽度（基于肩膀宽度在图像中的占比）
    
    Args:
        left_shoulder: 左肩膀坐标
        right_shoulder: 右肩膀坐标
        image_width: 图像宽度
    
    Returns:
        坐姿宽度比例（0-1之间）
    """
    shoulder_width = calculate_distance(left_shoulder, right_shoulder)
    
    if image_width == 0:
        return 0.0
    
    width_ratio = shoulder_width / image_width
    
    return min(width_ratio, 1.0)

def calculate_shoulder_elbow_angle(left_shoulder: Tuple[float, float],
                                   right_shoulder: Tuple[float, float],
                                   left_elbow: Tuple[float, float],
                                   right_elbow: Tuple[float, float]) -> float:
    """
    计算肩膀-肘部连线角度（评估手臂姿态）
    
    Args:
        left_shoulder: 左肩膀坐标
        right_shoulder: 右肩膀坐标
        left_elbow: 左肘部坐标
        right_elbow: 右肘部坐标
    
    Returns:
        肩膀-肘部连线与水平线的平均角度（度）
    """
    # 计算左侧肩膀-肘部连线角度
    left_vector = (left_elbow[0] - left_shoulder[0], left_elbow[1] - left_shoulder[1])
    left_angle = math.degrees(math.atan2(abs(left_vector[1]), abs(left_vector[0])))
    
    # 计算右侧肩膀-肘部连线角度
    right_vector = (right_elbow[0] - right_shoulder[0], right_elbow[1] - right_shoulder[1])
    right_angle = math.degrees(math.atan2(abs(right_vector[1]), abs(right_vector[0])))
    
    # 返回平均角度
    return (left_angle + right_angle) / 2

def calculate_shoulder_width_consistency(left_shoulder: Tuple[float, float],
                                        right_shoulder: Tuple[float, float],
                                        left_elbow: Tuple[float, float],
                                        right_elbow: Tuple[float, float]) -> float:
    """
    计算肩膀宽度一致性（左右肩膀到肘部距离的对称性）
    
    Args:
        left_shoulder: 左肩膀坐标
        right_shoulder: 右肩膀坐标
        left_elbow: 左肘部坐标
        right_elbow: 右肘部坐标
    
    Returns:
        宽度一致性差异值（0-1之间，0表示完全一致）
    """
    # 计算左侧肩膀到肘部距离
    left_distance = calculate_distance(left_shoulder, left_elbow)
    
    # 计算右侧肩膀到肘部距离
    right_distance = calculate_distance(right_shoulder, right_elbow)
    
    # 计算距离差异比例
    if left_distance + right_distance == 0:
        return 0.0
    
    distance_diff = abs(left_distance - right_distance)
    average_distance = (left_distance + right_distance) / 2
    
    consistency_diff = distance_diff / average_distance if average_distance > 0 else 0.0
    
    return min(consistency_diff, 1.0)

def calculate_head_shoulder_ratio(left_ear: Tuple[float, float],
                                 right_ear: Tuple[float, float],
                                 left_shoulder: Tuple[float, float],
                                 right_shoulder: Tuple[float, float]) -> float:
    """
    计算头肩比例（头部相对于肩膀的位置比例）
    
    Args:
        left_ear: 左耳坐标
        right_ear: 右耳坐标
        left_shoulder: 左肩膀坐标
        right_shoulder: 右肩膀坐标
    
    Returns:
        头肩比例值
    """
    # 计算耳朵中点和肩膀中点
    ear_center = ((left_ear[0] + right_ear[0]) / 2, (left_ear[1] + right_ear[1]) / 2)
    shoulder_center = ((left_shoulder[0] + right_shoulder[0]) / 2, 
                      (left_shoulder[1] + right_shoulder[1]) / 2)
    
    # 计算头部到肩膀的垂直距离
    vertical_distance = abs(ear_center[1] - shoulder_center[1])
    
    # 计算肩膀宽度作为参考
    shoulder_width = calculate_distance(left_shoulder, right_shoulder)
    
    if shoulder_width == 0:
        return 1.0
    
    # 计算头肩比例
    ratio = vertical_distance / shoulder_width
    
    return ratio

# 保留原有的头部角度计算函数，但降低其重要性
def calculate_head_forward_angle(nose: Tuple[float, float],
                               left_ear: Tuple[float, float],
                               right_ear: Tuple[float, float]) -> float:
    """
    计算头部前倾角度
    
    Args:
        nose: 鼻子位置
        left_ear: 左耳位置
        right_ear: 右耳位置
    
    Returns:
        头部前倾角度
    """
    # 计算耳朵中点
    ear_center = ((left_ear[0] + right_ear[0]) / 2, (left_ear[1] + right_ear[1]) / 2)
    
    # 计算头部前倾角度
    if nose[1] < ear_center[1]:  # 鼻子在耳朵上方
        angle = math.degrees(math.atan2(abs(nose[0] - ear_center[0]), 
                                       abs(ear_center[1] - nose[1])))
    else:  # 头部前倾
        angle = math.degrees(math.atan2(abs(nose[0] - ear_center[0]), 
                                       abs(nose[1] - ear_center[1])))
    
    return angle

def calculate_back_straightness(left_shoulder: Tuple[float, float],
                               right_shoulder: Tuple[float, float],
                               left_hip: Tuple[float, float],
                               right_hip: Tuple[float, float],
                               image_width: int) -> float:
    """
    计算背部挺直程度（基于肩膀宽度相对于图像的比例）
    
    Args:
        left_shoulder: 左肩位置
        right_shoulder: 右肩位置
        image_width: 图像宽度
    
    Returns:
        相对距离值 (0-1)
    """
    # 计算肩膀宽度
    shoulder_width = calculate_distance(left_shoulder, right_shoulder)
    
    # 基于肩膀宽度估算距离（肩膀越宽，距离越近）
    relative_width = shoulder_width / image_width
    
    # 将相对宽度转换为距离估算
    # 这里使用经验公式，实际应用中可能需要校准
    distance = max(0.1, min(1.0, 1.0 - relative_width * 2))
    
    return distance

def validate_landmarks(landmarks: List[Tuple[float, float]], 
                      required_points: List[int]) -> bool:
    """
    验证关键点是否有效
    
    Args:
        landmarks: 关键点列表
        required_points: 必需的关键点索引列表
    
    Returns:
        是否有效
    """
    if not landmarks or len(landmarks) == 0:
        return False
    
    for point_idx in required_points:
        if (point_idx >= len(landmarks) or 
            landmarks[point_idx][0] <= 0 or 
            landmarks[point_idx][1] <= 0):
            return False
    
    return True

def draw_landmarks(image: np.ndarray, 
                  landmarks: List[Tuple[float, float]], 
                  connections: Optional[List[Tuple[int, int]]] = None) -> np.ndarray:
    """
    在图像上绘制关键点和连接线
    
    Args:
        image: 输入图像
        landmarks: 关键点列表
        connections: 连接关系列表
    
    Returns:
        绘制后的图像
    """
    # 绘制关键点
    for point in landmarks:
        if point[0] > 0 and point[1] > 0:  # 只绘制有效点
            cv2.circle(image, (int(point[0]), int(point[1])), 5, COLORS['landmarks'], -1)
    
    # 绘制连接线
    if connections:
        for connection in connections:
            start_idx, end_idx = connection
            if (start_idx < len(landmarks) and end_idx < len(landmarks) and
                landmarks[start_idx][0] > 0 and landmarks[start_idx][1] > 0 and
                landmarks[end_idx][0] > 0 and landmarks[end_idx][1] > 0):
                
                start_point = (int(landmarks[start_idx][0]), int(landmarks[start_idx][1]))
                end_point = (int(landmarks[end_idx][0]), int(landmarks[end_idx][1]))
                cv2.line(image, start_point, end_point, COLORS['skeleton'], 2)
    
    return image

def draw_text_with_background(image: np.ndarray, 
                            text: str, 
                            position: Tuple[int, int], 
                            font_scale: float = 0.7,
                            font_thickness: int = 2,
                            text_color: Tuple[int, int, int] = (255, 255, 255),
                            bg_color: Tuple[int, int, int] = (0, 0, 0)) -> np.ndarray:
    """
    绘制带背景的文本
    
    Args:
        image: 输入图像
        text: 文本内容
        position: 文本位置 (x, y)
        font_scale: 字体大小
        font_thickness: 字体粗细
        text_color: 文本颜色
        bg_color: 背景颜色
    
    Returns:
        绘制后的图像
    """
    font = cv2.FONT_HERSHEY_SIMPLEX
    
    # 获取文本尺寸
    (text_width, text_height), baseline = cv2.getTextSize(text, font, font_scale, font_thickness)
    
    # 绘制背景矩形
    cv2.rectangle(image, 
                 (position[0] - 5, position[1] - text_height - 5),
                 (position[0] + text_width + 5, position[1] + baseline + 5),
                 bg_color, -1)
    
    # 绘制文本
    cv2.putText(image, text, position, font, font_scale, text_color, font_thickness)
    
    return image

def smooth_score(scores: List[float], window_size: int = 5) -> float:
    """
    使用移动平均平滑评分
    
    Args:
        scores: 评分历史列表
        window_size: 窗口大小
    
    Returns:
        平滑后的评分
    """
    if len(scores) < window_size:
        return np.mean(scores) if scores else 0.0
    
    return np.mean(scores[-window_size:])

def format_chinese_text(text: str) -> str:
    """
    格式化中文文本以便在OpenCV中正确显示
    
    Args:
        text: 原始文本
    
    Returns:
        格式化后的文本
    """
    # 这里可以添加中文字符处理逻辑
    # 目前简单返回原文本
    return text

def create_info_panel(width: int, height: int, 
                     metrics: any, 
                     suggestions: List[str]) -> np.ndarray:
    """
    创建信息面板
    
    Args:
        width: 面板宽度
        height: 面板高度
        metrics: 坐姿指标
        suggestions: 建议列表
    
    Returns:
        信息面板图像
    """
    panel = np.zeros((height, width, 3), dtype=np.uint8)
    
    # 绘制标题
    title = f"坐姿评分: {metrics.overall_score:.1f}/100"
    cv2.putText(panel, title, (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255, 255, 255), 2)
    
    # 绘制等级
    grade_text = f"等级: {metrics.grade}"
    cv2.putText(panel, grade_text, (10, 60), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (255, 255, 255), 2)
    
    # 绘制建议
    y_offset = 90
    for i, suggestion in enumerate(suggestions[:3]):  # 只显示前3个建议
        if len(suggestion) > 30:  # 如果建议太长，截断
            suggestion = suggestion[:30] + "..."
        cv2.putText(panel, suggestion, (10, y_offset + i * 25), 
                   cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 1)
    
    return panel 